home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / ucrasm27.zip / SOURCE.ZIP / INS1ST.ASM < prev    next >
Assembly Source File  |  1992-03-09  |  4KB  |  146 lines

  1.  
  2. ; Need to include "lists.a" in order to get list structure definition.
  3.  
  4.         include    lists.a
  5.         extrn    sl_malloc:far
  6.  
  7.  
  8. wp        equ    <word ptr>        ;I'm a lazy typist
  9.  
  10.  
  11. ; Special case to handle MASM 6.0 vs. all other assemblers:
  12. ; If not MASM 5.1 or MASM 6.0, set the version to 5.00:
  13.  
  14.         ifndef    @version
  15. @version    equ    500
  16.         endif
  17.  
  18.  
  19.  
  20. StdGrp        group    stdlib,stddata
  21. stddata        segment    para public 'sldata'
  22. stddata        ends
  23.  
  24. stdlib        segment    para public 'slcode'
  25.         assume    cs:stdgrp
  26.  
  27. ; sl_Insert1st -    DX:SI points at a list node.
  28. ;            ES:DI points at a list.
  29. ;            Insert the node at the beginning of the list
  30. ;
  31. ; Randall Hyde  3/4/92
  32. ;
  33.  
  34.         public    sl_Insert1st
  35. sl_Insert1st    proc    far
  36.         push    ds
  37.         push    es
  38.         push    di
  39.  
  40.         if    @version ge 600
  41.  
  42. ; MASM 6.0 version goes here
  43.  
  44.         mov    word ptr es:[di].List.CurrentNode, si
  45.         mov    word ptr es:[di+2].List.CurrentNode, dx
  46.  
  47.         mov    ds, dx
  48.         cmp    wp es:[di].List.Head+2, 0    ;Empty list?
  49.         jne    HasAList
  50.  
  51. ; At this point, the HEAD pointer is zero.  This only occurs if the
  52. ; list is empty.  So point the Head and Tail pointers to the new node.
  53. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  54. ; package assumes that if the segment is zero, the whole thing is zero.
  55. ; So don't put any nodes into segment zero!
  56.  
  57.         mov    wp es:[di].List.Head, si
  58.         mov    wp es:[di].List.Head+2, dx
  59.         mov    wp es:[di].List.Tail, si
  60.         mov    wp es:[di].List.Tail+2, dx
  61.         mov    wp ds:[si].Node.Next, 0            ;Set all the links
  62.         mov    wp ds:[si].Node.Next+2, 0    ; in the first node
  63.         mov    wp ds:[si].Node.Prev, 0        ; to NIL.
  64.         mov    wp ds:[si].Node.Prev+2, 0
  65.         pop     di
  66.         pop    es
  67.         pop    ds
  68.         jmp    InsertDone
  69.  
  70. ; If the HEAD pointer is non-NIL, insert the new node at the start of the
  71. ; list down here.
  72.  
  73. HasAList:    les    di, es:[di].List.Head        ;Get ptr to beginning
  74.         mov    wp es:[di].Node.Prev, si    ;Insert current node
  75.         mov    wp es:[di].Node.Prev+2, dx    ; at start of list.
  76.         mov    wp ds:[si].Node.Next, di    ;Link in back ptr.
  77.         mov    wp ds:[si].Node.Next+2, es
  78.         mov    wp ds:[si].Node.Prev, 0        ;Set PREV field of
  79.         mov    wp ds:[si].Node.Prev+2, 0    ; to NIL.
  80.         pop    di                ;Return ptr to list
  81.         pop    es                ; variable.
  82.         mov    wp es:[di].List.Head, si    ;Update last ptr.
  83.         mov    wp es:[di].List.Head+2, dx
  84.         pop    ds
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.         else
  92.  
  93. ; All other assemblers come down here:
  94.  
  95.         mov    word ptr es:[di].CurrentNode, si
  96.         mov    word ptr es:[di+2].CurrentNode, dx
  97.  
  98.         mov    ds, dx
  99.         cmp    wp es:[di].Head+2, 0        ;Empty list?
  100.         jne    HasAList
  101.  
  102. ; At this point, the HEAD pointer is zero.  This only occurs if the
  103. ; list is empty.  So point the Head and Tail pointers to the new node.
  104. ; Note: Technically, the NIL pointer is 32-bits of zero. However, this
  105. ; package assumes that if the segment is zero, the whole thing is zero.
  106. ; So don't put any nodes into segment zero!
  107.  
  108.         mov    wp es:[di].Head, si
  109.         mov    wp es:[di].Head+2, dx
  110.         mov    wp es:[di].Tail, si
  111.         mov    wp es:[di].Tail+2, dx
  112.         mov    wp ds:[si].Next, 0            ;Set all the links
  113.         mov    wp ds:[si].Next+2, 0        ; in the first node
  114.         mov    wp ds:[si].Prev, 0        ; to NIL.
  115.         mov    wp ds:[si].Prev+2, 0
  116.         pop     di
  117.         pop    es
  118.         pop    ds
  119.         jmp    InsertDone
  120.  
  121. ; If the HEAD pointer is non-NIL, insert the new node at the beginning of the
  122. ; list down here.
  123.  
  124. HasAList:    les    di, es:[di].Head        ;Get ptr to beginning
  125.         mov    wp es:[di].Prev, si        ;Insert current node
  126.         mov    wp es:[di].Prev+2, dx        ; at start of list.
  127.         mov    wp ds:[si].Next, di        ;Link in back ptr.
  128.         mov    wp ds:[si].Next+2, es
  129.         mov    wp ds:[si].Prev, 0        ;Set PREV field of
  130.         mov    wp ds:[si].Prev+2, 0        ; to NIL.
  131.         pop    di                ;Return ptr to list
  132.         pop    es                ; variable.
  133.         mov    wp es:[di].Head, si        ;Update last ptr.
  134.         mov    wp es:[di].Head+2, dx
  135.         pop    ds
  136.  
  137.         endif
  138.  
  139. InsertDone:
  140.         ret
  141.  
  142. sl_Insert1st    endp
  143.  
  144. stdlib        ends
  145.         end
  146.